  <%@ include  file="/other/Header.jsp" %>  
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<jsp:directive.page import="java.sql.*"/>
<jsp:directive.page import="Connectivity.ConnectionManager"/>
<%
String status = request.getParameter("status")!=null?request.getParameter("status"):"";
String empno = request.getParameter("employee_id")!=null?request.getParameter("employee_id"):"";
String callentryno= request.getParameter("callentry_id")!=null?request.getParameter("callentry_id"):"";
String callstype= request.getParameter("callstype")!=null?request.getParameter("callstype"):"OPEN";


%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
    
    <title> CallAssign </title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="/other/data.js"></script>
    
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>

  
 <script>
 
function insertParam(key, value) 
{    
	key = escape(key); value = escape(value);
    var kvp = document.location.search.substr(1).split('&');
 	if (kvp == '') 
 	{
 	document.location.search = '?' + key + '=' + value;
 	}
 	else 
 	{
 	var i = kvp.length; var x; while (i--) 
 	{
 	  x = kvp[i].split('='); 
 	if (x[0] == key) 
  {
   x[1] = value;
   kvp[i] = x.join('=');
   break;
  }
  }
  if (i < 0) 
  { kvp[kvp.length] = [key, value].join('='); }
        //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');         
  }
} 
function callDegree(obj)
{
		
		 if(obj.name=='callstype')
		 {insertParam((obj.name),(obj.value));}
		
	
 
			//document.callentry.action = "";
			//document.callentry.submit();
} 
</script>
  
  <body>
    <table border=1 width=80%>
    <form name=callassign action=temp.jsp method=get>
    <%
    if(status.equalsIgnoreCase("I"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> ASSIGNED SUCCESSFULLY </font> </td></tr>");
    }
     if(status.equalsIgnoreCase("U"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> UPDATED SUCCESSFULLY </font> </td></tr>");
    }
     if(status.equalsIgnoreCase("D"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> DELETED SUCCESSFULLY </font> </td></tr>");
    }
  String role_id1=""+(session.getAttribute("role_id")); 
 String calltypestaus="OPEN";
  if(role_id1.equals("1"))
  {
     %>
    <tr>
    <td align=right   colspan=5>
    <font size=2 color=Blue> 
    CALL STATUS TYPE :
    </font></td>
    <td align=left   colspan=5>
    <font size=2 color=Blue> 
    <select name="callstype"  onChange="callDegree(this);"  >
   <%if(callstype.equalsIgnoreCase("OPEN")){ %>
     <option value="OPEN" selected >OPEN</option>
    <option value="PFP" >PENDING FOR PARTS</option>
    <option value="MTAKEN" >MATERIAL TAKEN</option>
    <%}else if(callstype.equalsIgnoreCase("PFP"))
        {
    calltypestaus="PFP";
     %>
      <option value="OPEN"  >OPEN</option>
    <option value="PFP" selected>PENDING FOR PARTS</option>
     <option value="MTAKEN" >MATERIAL TAKEN</option>
<%}
else{ calltypestaus="MTAKEN";

%>

      <option value="OPEN"  >OPEN</option>
    <option value="PFP" >PENDING FOR PARTS</option>
     <option value="MTAKEN" SELECTED>MATERIAL TAKEN</option>

<%

}

 %>
    </select>
    </font></td></tr>
     <tr>
    <%} %>  
    <tr><td align=center   colspan=10><font size=4 color=Blue> CALL ASSIGN</font></td></tr>
     <tr>
     <td colspan=1><font size=2 color="light pink"><b>Sr.No.</b></font></td>
     <td colspan=1><font size=2 color="light pink"><b>COMPLAINT ID</b></font></td>
     <td colspan=1><font size=2 color="light pink"><b>CUSTOMER NAME</b></font></td>
     <td colspan=1><font size=2 color="light pink"><b>BRANCH</b></font></td>
     <td colspan=1><font size=2 color="light pink"><b>ISSUE</b></font></td>
     <td colspan=1><font size=2 color="light pink"><b>EMPLOYEE</b></font></td>
      </tr> 
      
     <%
     boolean flag=false;
     int count=0;
     String emp_eid="",call_details="";
     String compalint_id="-",customer_name="-",area="-",cust_type="-",callentry_id="";
    try
    {
    String employee="select emp_id,(name||' ' ||last_name) as emp_name from employee_master where role_id!=1 and  status='V'";
    
	// String calldisplay="		select ce.callentry_id,ce.complaint_id,cm.customer_name,cm.area,cn.name,coalesce(ce.call_details,'-')";
	//		calldisplay=calldisplay+" from callentry ce,customer_master cm,call_nature cn";
	//		calldisplay=calldisplay+" where ce.customer_id=cm.customer_id ";
 	//		calldisplay=calldisplay+" and  ce.call_nature_id=cn.call_nature_id ";
 	//		calldisplay=calldisplay+" "+calltypestaus;
 	//		calldisplay=calldisplay+" and ce.status='V'";
 	//		calldisplay=calldisplay+" order by ce.callentry_id";
 	CallableStatement cstmt = null;
		ResultSet calldisplayrs = null;
 
			cstmt = con.prepareCall("{?=call fun_retrieve_callentry(?,?)}");
			cstmt.registerOutParameter(1, Types.OTHER);
			cstmt.setString(2, calltypestaus);
			cstmt.setObject(3, calldisplayrs);
			
			con.setAutoCommit(false);
			cstmt.execute();
			
			calldisplayrs =(ResultSet) cstmt.getObject(1);	
 	
 	
 	
 	
 	
 	//String calldisplay="select function fun_retrieve_callentry("+calltypestaus+")";
    // PreparedStatement calldisplayprs=con.prepareStatement(calldisplay);
     //ResultSet calldisplayrs=calldisplayprs.executeQuery();
    while(calldisplayrs.next())
     {flag=true;count++;
     callentry_id= calldisplayrs.getString(1);
     compalint_id=calldisplayrs.getString(2);
     customer_name=calldisplayrs.getString(3);
     area=calldisplayrs.getString(4);
     cust_type=calldisplayrs.getString(5);
     call_details=calldisplayrs.getString(6);
   %>
   <tr>
    <td colspan=1><font size=2 color="BLACK"><%=count%></font></td>
    <td colspan=1><font size=2 color="BLACK"><%=compalint_id %></font></td>
    <td colspan=1><font size=2 color="BLACK"><%=customer_name %></font></td>
    <td colspan=1><font size=2 color="BLACK"><%=area %></font></td>
    <td colspan=1><font size=1 color="BLACK"><%=call_details.toUpperCase()%></font></td>           
    <td colspan=1>
    <select name="<%=("employee_id"+callentry_id)%>" >
    <option value="0">--select---</option>
    <%  
    PreparedStatement employeeprs=con.prepareStatement(employee);
    ResultSet employeers=employeeprs.executeQuery();
     while(employeers.next())  {
     emp_eid= employeers.getString(1);
     %>
    <option value=<%=(compalint_id+"#"+callentry_id+"#"+employeers.getString(1))%>><font size=1 color="BLACK"><%=employeers.getString(2) %></font></option>
   
    <%}%>
    </select>
     </td>
   
   </tr>
   
   
    
   <%} %>
   <tr>
   <td colspan=5 align="right"><input type= submit name=submit value="Assign"></td>
   <td colspan=5 align="left"><input type= reset name=reset value="reset"></td>
   </tr>
   
   
   </form>
   </table>
   <% 
    }
    catch(Exception e)
    {e.printStackTrace();}
    finally
    {
    con.close();
    } 
      %>
  </body>
</html>
